package com.tupu.service.impl.dispatch;

import com.tupu.entity.dispatch.*;
import com.tupu.mapper.dispatch.DadsJxdMapper;
import com.tupu.mapper.dispatch.DadsJxdYcsbztyqMapper;
import com.tupu.service.dispatch.WarningEventOverhaulService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;


@Service
public class WarningEventOverhaulServiceImpl implements WarningEventOverhaulService {

    @Autowired(required = false)
    private DadsJxdMapper dadsJxdMapper;

    @Autowired(required = false)
    private DadsJxdYcsbztyqMapper dadsJxdYcsbztyqMapper;

    @Override
    public WarningEventOverhaulDetails findByOverhaulId(String overhaulId) {
        DadsJxd jxd = dadsJxdMapper.selectById(overhaulId);
        WarningEventOverhaulDetails details = new WarningEventOverhaulDetails();
        details.setOverhaulId(overhaulId);
        if (StringUtils.isNotEmpty(jxd.getZxdd())){
            details.setDispatch(jxd.getZxdd());
        }
        //申请单类型
        if (StringUtils.isNotEmpty(jxd.getSqdlx())){
            details.setDeviceType(jxd.getSqdlx());
        }
        if (StringUtils.isNotEmpty(jxd.getGzc())){
            details.setSealService(jxd.getGzc());
        }
        if (StringUtils.isNotEmpty(jxd.getSqdbh())){
            details.setApplicationNum(jxd.getSqdbh());
        }
        if (StringUtils.isNotEmpty(jxd.getSqdw())){
            details.setApplicant(jxd.getSqdw());
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        if (null != jxd.getTjsj()) {
            String date = format.format(jxd.getTjsj());
            details.setSubmitTime(date);
        }
        if (StringUtils.isNotEmpty(jxd.getSqfzr())){
            details.setApplicanter(jxd.getSqfzr());
        }
        if (StringUtils.isNotEmpty(jxd.getSqrlxdh())){
            details.setPhone(jxd.getSqrlxdh());
        }
        if (StringUtils.isNotEmpty(jxd.getTdjxsb())){
            details.setEquipmentList(jxd.getTdjxsb());
        }
        if (StringUtils.isNotEmpty(jxd.getJxlb())){
            details.setOverhaulType(jxd.getJxlb());
        }
        //审批工作开始时间
        if (null != jxd.getPzgzkssj()){
            String date1 = format.format(jxd.getPzgzkssj());
            details.setWorkStartTime(date1);
        }
        //审批工作结束时间
        if (null != jxd.getPzgzjssj()){
            String date2 = format.format(jxd.getPzgzjssj());
            details.setWorkEndTime(date2);
        }
        if (StringUtils.isNotEmpty(jxd.getFsyj())){
            //方式意见
            details.setWayIdeaData(jxd.getFsyj());
        }
       if (StringUtils.isNotEmpty(jxd.getAzyj())){
           //安自意见
           details.setAZIdeaData(jxd.getAzyj());
       }
        //保护意见
        if (StringUtils.isNotEmpty(jxd.getBhyj())) {
            details.setProtectIdeaData(jxd.getBhyj());
        }
        //通信意见
        if (StringUtils.isNotEmpty(jxd.getTxyj())) {
            details.setTXIdeaData(jxd.getTxyj());
        }
        //自动化意见
        if (StringUtils.isNotEmpty(jxd.getZdhyj())) {
            details.setZDHIdeaData(jxd.getZdhyj());
        }
        //水调意见
        if (StringUtils.isNotEmpty(jxd.getSdyj())) {
            details.setWaterIdeaData(jxd.getSdyj());
        }
        //调度意见
        if (StringUtils.isNotEmpty(jxd.getDdyj())) {
            details.setDispatchIdeaData(jxd.getDdyj());
        }
        //批准意见
        if (StringUtils.isNotEmpty(jxd.getPzyj())) {
            details.setIsAgree(jxd.getPzyj());
        }
        //批准人
        if (StringUtils.isNotEmpty(jxd.getPzr())) {
            details.setAgreePeople(jxd.getPzr());
        }
        //通知时间
        Date time = jxd.getTzsj();
        if (null != time) {
            String date3 = format.format(time);
            details.setNoticeTime(date3);
        }
        //工作内容
        if (StringUtils.isNotEmpty(jxd.getGznr())) {
            details.setWorkContent(jxd.getGznr());
        }
        DadsJxdYcsbztyq ycsbztyq = dadsJxdYcsbztyqMapper.selectById(overhaulId);
        if (null != ycsbztyq){
            //工作要求的安全措施一次设备名称
            details.setSbmc(ycsbztyq.getSbmc());
            //工作要求的安全措施一次设备状态
            details.setSbmc(ycsbztyq.getSbzt());
        }
        return details;
    }
}
